/*
 *  Copyright 2008-2010 www.jrails.org
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

package org.rails.extjs;

import java.util.ArrayList;
import java.util.List;


public abstract class Component extends Observable {
	
	public final static String HIDE_MODE_VISIBILITY = "visibility";
	public final static String HIDE_MODE_OFFSETS = "offsets";
	public final static String HIDE_MODE_DISPLAY = "display";
	
	protected List<AbsBase> plugins = new ArrayList<AbsBase>();
	
	public Component() {
		super();
		setId(createId());
	}
	
	public Component(Option configOptions){
		this.option = configOptions;
	}

	public Component(String id) {
		super();
		setId(id);
	}
	
	@Override
	protected void createItems(){
		super.createItems();
		if(plugins.size() > 0)
			addOption("plugins",plugins);
	}
	
	public void addPlugin(AbsBase base){
		plugins.add(base);
	}
	
	public AbsBase getPlugin(int index){
		return plugins.get(index);
	}
	
	public void removePlugin(int index){
		plugins.remove(index);
	}
	
	public void clearPlugin(){
		plugins.clear();
	}
	
	public List<AbsBase> getPlugins(){
		return plugins;
	}
	
	public void setAllowDomMove(Boolean allowDomMove){
		addOption("allowDomMove",allowDomMove);
	}
	
	public Boolean isAllowDomMove(){
		return getBoolean("allowDomMove",true);
	}
	
	public void setAnchor(String anchor){
		addOption("anchor",anchor);
	}
	
	public String getAnchor(){
		return getString("anchor","");
	}
	
	public void setAutoShow(Boolean autoShow){
		addOption("autoShow",autoShow);
	}
	
	public Boolean isAutoShow(){
		return getBoolean("autoShow",false);
	}
	
	public void setClearClassName(String className){
		addOption("clearCls",className);
	}
	
	public String getClearClassName(){
		return getString("clearCls","x-form-clear-left");
	}
	
	public void setClassName(String className){
		addOption("cls",className);
	}
	
	public String getClassName(){
		return getString("cls","");
	}
	
	public void setCTClassName(String ctClassName){
		addOption("ctCls", ctClassName);
	}
	
	public String getCTClassName(){
		return getString("ctCls","");
	}
	
	public void setDisabled(Boolean disabled){
		addOption("disabled",disabled);
	}
	
	public Boolean isDisabled(){
		return getBoolean("disabled",false);
	}
	
	public void setDisabledClassName(String disabledClassName){
		addOption("disabledClass",disabledClassName);
	}
	
	public String getDisabledClassName(){
		return getString("disabledClass","x-item-disabled");
	}
	
	public void setFieldLabel(String fieldLabel){
		addOption("fieldLabel",fieldLabel);
	}
	
	public String getFieldLabel(){
		return getString("fieldLabel","");
	}
	
	public void setHidden(Boolean hidden){
		addOption("hidden",hidden);
	}
	
	public Boolean isHidden(){
		return getBoolean("hidden",false);
	}
	
	public void setHideLabel(Boolean hideLabel){
		addOption("hideLabel",hideLabel);
	}
	
	public Boolean isHideLabel(){
		return getBoolean("hideLabel",false);
	}
	
	public void setHideMode(String hideMode){
		addOption("hideMode",hideMode);
	}
	
	public String getHideMode(){
		return getString("hideMode","display");
	}
	
	public void setHideParent(Boolean hideParent){
		addOption("hideParent",hideParent);
	}
	
	public Boolean isHideParent(){
		return getBoolean("hideParent",false);
	}
	
	public void setLabelSeparator(String labelSeparator){
		addOption("labelSeparator",labelSeparator);
	}
	
	public String getLabelSeparator(){
		return getString("labelSeparator",":");
	}
	
	public void setLabelStyle(String labelStyle){
		addOption("labelStyle",labelStyle);
	}
	
	public String getLabelStyle(){
		return getString("labelStyle","");
	}
	
	public void setOverClassName(String overClassName){
		addOption("overCls", overClassName);
	}
	
	public String getOverClassName(){
		return getString("overCls","");
	}
	
	public void setStyle(String style){
		addOption("style",style);
	}
	
	public String getStyle(){
		return getString("style","");
	}
	
	public void setRef(String ref){
		addOption("ref",ref);
	}
	
	public String getRef(){
		return getString("ref","");
	}
	
	public void setStateEvents(List<String> stateEvents){
		addOption("stateEvents",stateEvents);
	}
	
	@SuppressWarnings("unchecked")
	public List<String> getStateEvents(){
		return (List<String>)getOption("stateEvents");
	}
	
	public void setStateId(String stateId){
		addOption("stateId", stateId);
	}
	
	public String getStateId(){
		return getString("stateId","");
	}
	
	public void setStateful(Boolean stateful){
		addOption("stateful", stateful);
	}
	
	public Boolean isStateful(){
		return getBoolean("stateful",false);
	}
	
	public void setRenderTo(String mixed){
		addOption("renderTo",mixed);
	}
	
	public void setApplyTo(String applyTo){
		addOption("applyTo",applyTo);
	}	
	
	public void setId(String id) {
		addOption("id", id);
	}
	
	public String getId() {
		return getString("id","");
	}
	
	public void clearId(){
		option.remove("id");
	}
	

}
